<template>
	<DataList ref="DataListRef" :api="discussList" :columns="discussColumns" @onOperation="onOperation"
		:query="queryUserForm" />
</template>
<script setup>
import { discussList, discussDelete } from "@/api/discuss";
import { discussColumns, queryUserForm } from "./constant"
import { ElMessage, ElMessageBox } from 'element-plus'

import { ref } from 'vue';

const DataListRef = ref(null)

// 点击操作列回调函数
function onOperation(e) {
	let { key, rowData } = e;
	if (key == 'delete') {
		onDiscussDelete([rowData.row.id])
	}
}

// 删除话题
function onDiscussDelete(ids) {
	ElMessageBox.confirm('是否确认删除？', '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning'
	}).then(() => {
		discussDelete({
			ids
		}).then(res => {
			if (res.code == 1) {
				ElMessage({
					type: 'success',
					message: '删除成功',
				})

				DataListRef.value.getList()
			}
		})
	})
}
</script>
<style></style>